package com.xhgj.thread;

/**
 * @author 周宇
 * @create 2020-06-28 0:00
 * 测试守护线程
 */
public class DaemonThread {
    public static void main(String[] args) {
        God god = new God();
        You you = new You();
        Thread thread = new Thread(god);
        thread.setDaemon(true);//默认是false 用户线程，这里设置为true 守护线程
        thread.start();//上帝守护线程启动

        new Thread(you).start();//你 用户线程启动
    }
}

//上帝
class God implements Runnable {
    @Override
    public void run() {
        while (true) {
            System.out.println("上帝保佑着你");
        }
    }
}

//你 人生不过3w天
class You implements Runnable {
    @Override
    public void run() {
        //100年
        for (int i = 0; i < 36500; i++) {
            System.out.println("你一生都开心的活着");
        }
        System.err.println("============goodbye world!");//Hello World!
    }
}
